package com.ww.springboot.boot.java8.completablefuture;

import org.springframework.scheduling.concurrent.CustomizableThreadFactory;

import java.sql.Time;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * todo
 *
 * @author wanwei
 * @since 2021-04-28 17:17
 */
public class CompletableFutureDemo8 {

    private static final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors() * 2, Runtime.getRuntime().availableProcessors() * 2,
            10, TimeUnit.SECONDS, new LinkedBlockingDeque<>(), new CustomizableThreadFactory("platformStore-thread-pool"));

    static volatile StringBuilder ss = new StringBuilder();

    public static void main(String[] args) throws InterruptedException, ExecutionException, TimeoutException {

        CompletableFuture completableFuture = CompletableFuture.runAsync(() -> {
            ss.append("子线程-开始" + "\n");
            //System.out.println("子线程-开始");
            //TimeUnit.SECONDS.sleep(2);
            ss.append("子线程-结束" + "\n");
            //System.out.println("子线程-结束");
        }, threadPoolExecutor);

        ss.append("主线程开始" + "\n");
        completableFuture.get();
        ss.append("主线程结束" + "\n");

        TimeUnit.SECONDS.sleep(2);

        System.out.println(ss);
    }
}
